Skip to content

Conversation

@noahsmartin
Copy link
Contributor

@noahsmartin noahsmartin commented Nov 25, 2025

Fixes #4040

The problem was that for some events such as app hangs and CPUDiagnostics the metric kit payload contains an entire flamegraph. This change parses the flame graph into samples, and then picks the longest duration sample as the one we use for a stack trace. It also fixes over-counting the CPUDiagnostics which was emitting more than one event per exception. This is also fixed by identifying the longest duration sample.

Eventually we should support showing the full flame graph on the frontend, but with this PR the bug is fixed and we can consider that a future improvement.

I tested this on test flight by triggering crashes and verifying they are still correct

@noahsmartin noahsmartin added the ready-to-merge Use this label to trigger all PR workflows label Nov 25, 2025
@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.037%. Comparing base (b2295d4) to head (a7949ab).
⚠️ Report is 26 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #6908       +/-   ##
=============================================
- Coverage   85.076%   85.037%   -0.039%     
=============================================
  Files          453       455        +2     
  Lines        27674     27690       +16     
  Branches     12166     12160        -6     
=============================================
+ Hits         23544     23547        +3     
- Misses        4087      4099       +12     
- Partials        43        44        +1     
Files with missing lines Coverage Δ
Sources/Sentry/SentryFormatterSwift.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryMetricKitIntegration.m 100.000% <100.000%> (ø)
...s/Swift/Core/MetricKit/SentryMXCallStackTree.swift 100.000% <100.000%> (+25.000%) ⬆️
Sources/Swift/Core/MetricKit/SentryMXManager.swift 100.000% <100.000%> (ø)

... and 42 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2295d4...a7949ab. Read the comment docs.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1222.17 ms 1257.09 ms 34.92 ms
Size 24.14 KiB 1.03 MiB 1.00 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
762a701 1225.95 ms 1244.49 ms 18.54 ms
61414e8 1225.49 ms 1254.28 ms 28.79 ms
588dd7c 1235.11 ms 1241.76 ms 6.65 ms
f5666e7 1227.08 ms 1260.18 ms 33.10 ms
b9aacb6 1230.42 ms 1251.00 ms 20.58 ms
16f6edc 1234.02 ms 1269.67 ms 35.65 ms
b709887 1193.52 ms 1216.74 ms 23.22 ms
5fc3364 1222.36 ms 1252.33 ms 29.96 ms
1fe932f 1231.92 ms 1253.44 ms 21.52 ms
80538ca 1216.70 ms 1253.92 ms 37.22 ms

App size

Revision Plain With Sentry Diff
762a701 23.75 KiB 1022.78 KiB 999.03 KiB
61414e8 23.75 KiB 867.69 KiB 843.94 KiB
588dd7c 23.75 KiB 938.33 KiB 914.58 KiB
f5666e7 23.75 KiB 963.18 KiB 939.43 KiB
b9aacb6 23.75 KiB 913.64 KiB 889.89 KiB
16f6edc 23.74 KiB 1022.94 KiB 999.19 KiB
b709887 23.75 KiB 1.01 MiB 1016.14 KiB
5fc3364 23.75 KiB 1.00 MiB 1006.00 KiB
1fe932f 23.75 KiB 913.63 KiB 889.88 KiB
80538ca 23.75 KiB 989.99 KiB 966.24 KiB

Previous results on branch: mxRewriting

Startup times

Revision Plain With Sentry Diff
44da6c5 1234.22 ms 1266.02 ms 31.80 ms
8824c94 1226.98 ms 1262.65 ms 35.67 ms
c5b3f7a 1220.18 ms 1259.44 ms 39.25 ms

App size

Revision Plain With Sentry Diff
44da6c5 24.14 KiB 1.03 MiB 1.00 MiB
8824c94 24.14 KiB 1.01 MiB 1014.88 KiB
c5b3f7a 24.14 KiB 1.01 MiB 1013.45 KiB

@noahsmartin noahsmartin force-pushed the mxRewriting branch 2 times, most recently from d978079 to 169cf94 Compare December 1, 2025 20:59
@noahsmartin noahsmartin force-pushed the mxRewriting branch 2 times, most recently from 432f4ad to a7949ab Compare December 10, 2025 22:32
@noahsmartin noahsmartin marked this pull request as ready for review December 11, 2025 00:31
[self captureMXEvent:callStackTree
params:params
diagnosticJSON:[diagnostic JSONRepresentation]];
[self captureMXEvent:callStackTree params:params diagnosticJSON:[NSData data]];

This comment was marked as outdated.

// that just contains the most common callstack.
func sentryMXBacktrace(inAppLogic: SentryInAppLogic?, handled: Bool) -> [SentryThread] {
callStacks.map { callStack in
let thread = SentryThread(threadId: 0)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: All threads incorrectly assigned thread ID 0

In sentryMXBacktrace(), all threads are assigned threadId: 0 regardless of their position in the callStacks array. The old Objective-C code used an incrementing counter to assign unique thread IDs (@(i)). When callStackPerThread is true (e.g., for crash diagnostics), multiple call stacks represent different threads and need distinct IDs. Using callStacks.enumerated().map would provide the index needed for unique thread IDs.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK wrongly parses MetricKit MXHangDiagnostic stack trace

2 participants